<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>商品列表</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<link rel="stylesheet" href="__PEAR__/admin/css/other/department.css"/>
	</head>
	<body class="pear-container">
	<!-- 使用改包含页面之前，必须首先引入layui和pear -->
	<div class="layui-row layui-col-space15">
			<div class="layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-body">
						<div id="goodClassTreeContent" style="overflow: auto;">
							<ul id="goodClassTree" class="dtree goodClassTree"></ul>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-col-md9">
				<div class="layui-card">
					
					<div class="layui-card-body" style="width:100%;overflow-x:scroll">
						<form class="layui-form" action="">
							<div class="layui-form-item" style="margin-bottom:0;">
								<div class="layui-form-item layui-inline">
									<label class="layui-form-label">搜索</label>
									<div class="layui-input-inline"  style="width:350px">
										<input type="text" id="keyword" name="keyword" placeholder="商品编号、商品名称、分类编号" class="layui-input"/>
									</div>
								</div>
								
								<div class="layui-form-item layui-inline">
									<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="goodsItem-query">
										<i class="layui-icon layui-icon-search"></i>
										查询
									</button>
									<button type="button" class="pear-btn pear-btn-md pear-btn-warming" id="callback">
										<i class="pear-icon pear-icon-back"></i>
										确定返回
									</button>
								</div>
							</div>
					</form>
						<table id="goodsItem-table" lay-filter="goodsItem-table"></table>
					</div>
				</div>
			</div>
		</div>
		<input type="hidden" value="0" id="hidSupcust" />
		<input type="hidden" value="0" id="hidCombine" />
		<input type="hidden" value="1" id="hidMutiSelect" />
		<input type="hidden" value="0" id="hidCurrentBranch" />
		<input type="hidden" value="0" id="hidStock" />
		<script type="text/html" id="goodItem-toolbar">
			
		</script>

		<script type="text/html" id="goodItem-bar">
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
				class="layui-icon layui-icon-delete"></i></button>
	    </script>
		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script src="__STATIC__/js/admin/common.js"></script>
		<script>
			var _parent="";
			
			layui.use(['table', 'form', 'jquery', 'dtree'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let dtree = layui.dtree;
				
				_parent='';
				
				let MODULE_PATH = "/{$MODULE_NAME}/common/";
				let DATA_PATH = MODULE_PATH+"index/";
				let TREE_PATH=DATA_PATH+"itemClass";

				let cols = [
					[
						{
							type: 'radio',
							fixed:'left'
						},
						{
							title: '商品货号',
							field: 'item_no',
							align: 'left',
							width:180,
							fixed:'left'
						},
						{
							title: '商品名称',
							field: 'item_name',
							align: 'left',
							width:200,
						},
						{
							title: '分类编号',
							field: 'item_clsno',
							align: 'left'
						},
						{
							title: '单位',
							field: 'unit_no',
							align: 'left'
						},
						{
							title: '规格',
							field: 'item_size',
							align: 'left'
						},
						{
							title: '产地',
							field: 'product_area',
							align: 'left'
						},
						{
							title: '进货价',
							field: 'item_price',
							align: 'left',
							fixed:"right"
						},
						{
							title: '建议售价',
							field: 'sale_price',
							align: 'left'
						},
						{
							title: '进货规格',
							field: 'purchase_spec',
							align: 'left'
						}
					]
				]
				
				var DTree = dtree.render({
					elem: "#goodClassTree",
					height:"full-25",
					initLevel: "2", //默认展开层级为1
					line: true, // 有线树
					ficon: ["1", "-1"], // 设定一级图标样式。0表示方形加减图标，8表示小圆点图标
					icon: ["0", "0"], // 设定二级图标样式。0表示文件夹图标，5表示叶子图标
					method: 'get',
					url: TREE_PATH
				});

				table.render({
					elem: '#goodsItem-table',
					url: DATA_PATH+'getItemInfo',
					width:750,
					height: 430,
					cellMinWidth: 100,
					page: true,
					cols: cols,
					skin: 'line',
					toolbar: false,
					defaultToolbar: []
				});

				// 绑定节点点击事件
				dtree.on("node(goodClassTree)", function(obj) {
					_parent=obj.param.nodeId;
					//console.log(obj.param.nodeId);
					var _keyword=$("#keyword").val();
					table.reload("goodsItem-table",{
							where:{'item_clsno':_parent,'keyword':_keyword}
					});
					
				});

				form.on('submit(goodsItem-query)', function(data) {
					//console.log(data.field.keyword);
					var _keyword=data.field.keyword;
					table.reload('goodsItem-table', {
						where: {'item_clsno':_parent,'keyword':_keyword},
						page:{curr:1}
					})
					return false;
				});
				
				var  active = {
						getCheckData: function(){ //获取选中数据
						      var checkStatus = table.checkStatus('goodsItem-table')
						      					,data = checkStatus.data;
								if(data.length ==0){
									layer.msg("请选择商品");
									return;
								}
								
								parent.callBack(data);
						      
					    }
				}
				//确认返回按钮点击事件
				$('#callback').on('click', function(){
					     active['getCheckData'].call(this);
					     return;
				});
			})
		</script>
	</body>
</html>